package com.small.web;

import java.util.HashMap;
import java.util.Map;

/**
 * 视图模型对象：存放了Controller返回的视图和模型数据
 * Created by fangzheng on 2018/1/31.
 */
public class ModelAndView {
    private Map<String, Object> data;
    private String path;

    public ModelAndView() {
        this.data = new HashMap<String, Object>();
    }

    public ModelAndView(String path) {
        this.data = new HashMap<String, Object>();
        this.path = path;
    }

    /**
     * 添加视图
     *
     * @param viewPath
     * @return
     */
    public ModelAndView addView(String viewPath) {
        this.path = viewPath;
        return this;
    }

    /**
     * 添加单个数据
     *
     * @param key
     * @param value
     * @return
     */
    public ModelAndView addModel(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    /**
     * 添加多个数据
     *
     * @param model
     * @return
     */
    public ModelAndView addModels(Map<String, Object> model) {
        this.data.putAll(model);
        return this;
    }

    /**
     * 返回所有模型数据
     *
     * @return
     */
    public Map<String, Object> getModel() {
        return data;
    }

    /**
     * 返回视图路径
     *
     * @return
     */
    public String getPath() {
        return path;
    }
}
